// import {createStore} from 'redux';
// //通过reduce建立
// //根据老得state和action生成新的state
// function counter (state=0,action) {
//     switch (action.type) {
//         case 'add' :
//             return state+1
//         case 'minus':
//             return state-1
//         default:
//             return 10
//     }
// }

// // 1、新建store
// const store = createStore(counter);
// const init = store.getState();
// console.log(init)
// function listener() {
//     const current = store.getState();
//     console.log(`现在有机关枪${current}`)
// }

// store.subscribe(listener)

// //派发事件
// store.dispatch({type:'add'});
// console.log(store.getState());
// store.dispatch({type:'add'});
// console.log(store.getState());
// store.dispatch({type:'minus'});
// console.log(store.getState());


import React from 'react'
import ReactDom from 'react-dom'
//引入路由
import { BrowserRouter,Route, Redirect, Switch} from 'react-router-dom'

//引入redux框架
//createStore-创建store
import {createStore,applyMiddleware,compose} from 'redux';
//thunk-异步处理action
import thunk from 'redux-thunk';
//连接react 和 redux之间的关系
import {Provider} from 'react-redux';
// import {counter,addGun,removeGun,addGunAsync} from './index.redux'


// import {counter} from './index.redux'
//导入所有合并的reducer；
import Reducers from './reducer/reducers'

//axios拦截器
import './config'
import App from './app';

//导入自组件
import Auth from './auth/auth';
import Order from './components/order';
import Payment from './components/payment';
import Customer from './components/customer';
import Test from './components/test';
import NotFound from './components/NotFound';

console.log(Reducers)
const store = createStore(Reducers,compose(
    applyMiddleware(thunk),
    window.devToolsExtension?window.devToolsExtension():f=>f

))
console.log(store.getState())

// const init = store.getState();
// console.log(init)

// function render() {
//     ReactDOM.render(
//         <App  store = {store} addGun={addGun} removeGun={removeGun} addGunAsync={addGunAsync}/>,
//         document.querySelector('#root')
//     )
// }
// render();
// store.subscribe(render);

//登陆

//页面
    //促销
    //订单
    //客户
    //支付





    ReactDom.render(
        (<Provider store = {store}>
            <BrowserRouter>
                <div>

                    <Switch>
                        <Route path='/' exact component={App}></Route>
                        <Route path='/login' exact component={Auth}></Route>
                        <Route path='/order/:location'  component={Test}></Route>
                        <Route path='/order' component={Order}></Route>
                        <Route path='/payment' component={Payment}></Route>
                        <Route path='/customer' component={Customer}></Route>
                        <Route path='/:location' component={Test}></Route>
                        <Route path='/notfound' component={NotFound}></Route>
                        <Redirect to='/NotFound' ></Redirect>
                    </Switch>
                </div>
            </BrowserRouter>
        </Provider>),
        document.querySelector('#root')
    )